<template>
    <div>
        <el-table
            ref="customerTable"
            :data="tableData"
            stripe
            style="width: 100%"
            @selection-change="getSelectVal"
        >
            <el-table-column type="selection" width="55" align="center">
            </el-table-column>
            <el-table-column
                type="index"
                label="序号"
                width="55"
                align="center"
            />
            <el-table-column prop="customerName" label="客户名称">
                <template slot-scope="scope">
                    {{ scope.row.customerName || "--" }}
                </template>
            </el-table-column>
            <el-table-column prop="telPhone" label="电话">
                <template slot-scope="scope">
                    {{ scope.row.telPhone || "--" }}
                </template>
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间">
                <template slot-scope="scope">
                    {{ scope.row.createTime || "--" }}
                </template>
            </el-table-column>
            <el-table-column prop="state" label="状态">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.state === '0'"
                        >正常</el-tag
                    >
                    <el-tag type="danger" v-else-if="scope.row.state === '1'"
                        >异常</el-tag
                    >
                    <span v-else>--</span>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            class="pagination mt10"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
        >
        </el-pagination>
    </div>
</template>

<script>
import { getCustomerList } from "@/api/base/data";
export default {
    data() {
        return {
            tableData: [],
            currentPage: 1, //当前页
            pageSize: 10, //每页条数
            total: 0,
        };
    },
    methods: {
        //分页器size
        handleSizeChange(val) {
            this.pageSize = val;
            this.getDataList();
        },
        //分页器当前页
        handleCurrentChange(val) {
            this.currentPage = val;
            this.getDataList();
        },
        getSelectVal(val) {
            this.$emit("getSelectVal", val);
        },
        getDataList() {
            getCustomerList().then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
            });
        },
    },
    mounted() {
        this.getDataList();
    },
};
</script>

<style></style>
